package test;
//File Name SendFileEmail.java

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.eschool.dao.UserDao;
import com.eschool.model.User;
import com.eschool.service.AlertService;
import com.eschool.service.impl.AlertServiceImpl;

public class EmailTest2
{
public static void main(String [] args)
{
	AlertService service = new AlertServiceImpl();
	
	List<User> reciepients = new ArrayList<User>();
	
	reciepients.add(UserDao.getUserByProperty("userId", 1));
	//reciepients.add(UserDao.getUserByProperty("userId", 2));
	//reciepients.add(UserDao.getUserByProperty("userId", 3));
	
	/*
	User nisar = new User();
	nisar.setEmail("nisar.ahmed157@gmail.com");
	reciepients.add(nisar);
	*/
	String message = "Test message sent at " + new Date();
	
	if(service.sendAlert("Test Alert", message, reciepients, "C:/Users/Ammar/Desktop/Ammar Resume - SEECS .doc"))
		System.out.print("Done");
	
	/*
   String to = "asim.ammar@gmail.com";

   String from = "eschool.cloud@gmail.com";
   
   final String username = "eschool.cloud@gmail.com";
   
	final String password = "eschool@cloud";

	Properties props = new Properties();
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.starttls.enable", "true");
	props.put("mail.smtp.host", "smtp.gmail.com");
	props.put("mail.smtp.port", "587");


	Session session = Session.getInstance(props,
			  new javax.mail.Authenticator() {
				protected PasswordAuthentication getPasswordAuthentication() {
					return new PasswordAuthentication(username, password);
				}
			  });

   try{
      // Create a default MimeMessage object.
      MimeMessage message = new MimeMessage(session);

      // Set From: header field of the header.
      message.setFrom(new InternetAddress(from));

      List<String> addresses = new ArrayList<String>();
      
      addresses.add(to);
      addresses.add("08bitammara@seecs.edu.pk");
      
      List<InternetAddress> a = new ArrayList<InternetAddress>();
      
      for (Iterator iterator = addresses.iterator(); iterator.hasNext();) {
		InternetAddress internetAddress = new InternetAddress(((String)iterator.next()));
		a.add(internetAddress);
	}
      
      InternetAddress[] addrList ;
      
      addrList = new InternetAddress[2];
      
      addrList[0] =  new InternetAddress(to);
      addrList[1] =  new InternetAddress("08bitammara@seecs.edu.pk");
    	  
      
      message.setRecipients(Message.RecipientType.TO, addrList);
      message.setSubject("This is the Subject Line!");

      // Create the message part 
      BodyPart messageBodyPart = new MimeBodyPart();

      // Fill the message
      messageBodyPart.setText("This is message body");
      
      // Create a multipar message
      Multipart multipart = new MimeMultipart();

      // Set text message part
      multipart.addBodyPart(messageBodyPart);

      // Part two is attachment
      messageBodyPart = new MimeBodyPart();
      String filename = "C:/Users/Ammar/Desktop/Ammar Resume - SEECS .doc";
      DataSource source = new FileDataSource(filename);
      messageBodyPart.setDataHandler(new DataHandler(source));
      messageBodyPart.setFileName("Resume.doc");
      multipart.addBodyPart(messageBodyPart);

      // Send the complete message parts
      message.setContent(multipart );

      // Send message
      Transport.send(message);
      System.out.println("Sent");
   }catch (MessagingException mex) {
	   System.out.println("Not Sent");
      mex.printStackTrace();
   }*/
}
}